﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZJ_XZMJBCJInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox txtID, txtPID, txt单据编号, txt身份证号, txt缴纳人, txt缴纳金额, txt缴纳银行, 立项号, txt备注;
        MPCalendar txt缴纳时间, txt兑付时间;
        DropDownList ddl兑付情况;
        string strid;
        Button btn_Insert;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
            if (!base.Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(strid))
                {
                    txtID.Text = strid;
                    EluZSProvider.ADDAREA addarea = _EluZSDataProvider.GetADDAREA(strid);
                    txtPID.Text = addarea.PID;

                    txt单据编号.Text = addarea.单据编号;
                    txt身份证号.Text = addarea.身份证号;
                    txt缴纳人.Text = addarea.缴纳人;
                    txt缴纳金额.Text = addarea.缴纳金额;
                    txt缴纳银行.Text = addarea.缴纳银行;

                    txt备注.Text = addarea.备注;
                    if (addarea.缴纳时间.HasValue) { txt缴纳时间.Text = addarea.缴纳时间.Value.ToShortDateString(); }
                    if (addarea.兑付时间.HasValue) { txt兑付时间.Text = addarea.兑付时间.Value.ToShortDateString(); }
                    ddl兑付情况.SelectedValue = addarea.兑付情况;
                    if (!string.IsNullOrEmpty(addarea.PID)) {
                        立项号.Text = _EluZSDataProvider.GetSomeStr("zs_project", "立项号", "id", addarea.PID);
                    }
                }
                else
                {
                    txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "");
                }
            }
            IsLookPerson();
        }


        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btn_Insert =(Button)FindControl("btn_Insert");
                        btn_Insert.Visible = false;
                    }
                }
            }
        }

        protected void InitControl() {
            txtID = (TextBox)FindControl("txtID");
            txtPID = (TextBox)FindControl("txtPID");
            txt单据编号 = (TextBox)FindControl("txt单据编号");
            txt身份证号 = (TextBox)FindControl("txt身份证号");
            txt缴纳人 = (TextBox)FindControl("txt缴纳人");

            txt缴纳金额 = (TextBox)FindControl("txt缴纳金额");
            txt缴纳银行 = (TextBox)FindControl("txt缴纳银行");
            立项号 = (TextBox)FindControl("立项号");
            txt备注 = (TextBox)FindControl("txt备注");

            txt缴纳时间 = (MPCalendar)FindControl("txt缴纳时间");
            txt兑付时间 = (MPCalendar)FindControl("txt兑付时间");
            ddl兑付情况 = (DropDownList)FindControl("ddl兑付情况");
            strid = base.Page.Request["ID"];
            btn_Insert = (Button)FindControl("btn_Insert");
        }
        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            EluZSProvider.ADDAREA addarea = new EluZSProvider.ADDAREA();
            addarea.ID = txtID.Text.Trim();
            addarea.PID = txtPID.Text.Trim();

            addarea.单据编号 = txt单据编号.Text.Trim();
            addarea.身份证号 = txt身份证号.Text.Trim();
            addarea.缴纳人 = txt缴纳人.Text.Trim();
            addarea.缴纳金额 = txt缴纳金额.Text.Trim();
            addarea.缴纳银行 = txt缴纳银行.Text.Trim();
            addarea.备注 = txt备注.Text;
            addarea.缴纳时间 = (string.IsNullOrEmpty(txt缴纳时间.Text) ? null : (DateTime?)Convert.ToDateTime(txt缴纳时间.Text));
            addarea.兑付时间 = (string.IsNullOrEmpty(txt兑付时间.Text) ? null : (DateTime?)Convert.ToDateTime(txt兑付时间.Text));
            addarea.兑付情况 = ddl兑付情况.SelectedValue;

            bool save = _EluZSDataProvider.SaveAddarea(strid, addarea);
            if (save) { base.Page.Response.Write("<script>alert('保存成功！');window.location.href('ZJ_XZMJBCJInfo.aspx?ID=" + txtID.Text + "');</script>"); }
        }
    }
}


